package
{
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.display.*;
	import Player;
	import PauseModule;
	import QuitModule;
	import mcUISkin;
	
	public class UIMain extends UI
	{
		
		private var player:Player;
		private var skin:mcUISkin;
		private var pModule:PauseModule;
		private var qModule:QuitModule;
		
		public function UIMain(p:Player)
		{
			
			super();
			player = p;
			
		}
		
		override public function init(p:Player)
		{
			
			destroy();
			skin = new mcUISkin();
			addChild(skin);
			qModule.destroy();
			qModule.visible = false;
			pModule.destroy();
			pModule.visible = false;
			skin.strEquippedGun_T1.text = p.account.data.strEquippedGun;
			skin.strMoney_T1.text = Utility.formatNumberStringWithCommas(p.account.data.intCash);
			skin.strHP_I.text = "HP: " + p.account.data.intHP + "/" + p.account.data.intHPMax;
			skin.mcHPBar.width = Math.round(30 * (p.account.data.intHP / p.account.data.intHPMax));
			skin.strRounds_T1.text = p.account.data.equippedGun.intRemainingRounds + " Rounds";
			btnPause.addEventListener(MouseEvent.CLICK, onPauseClick);
			btnMusic.addEventListener(MouseEvent.CLICK, onMusicClick);
			stage.addEventListener(KeyboardEvent.KEYBOARD, onKeyboardChk);
			
		}
		
		override public function destroy():void
		{
			
			trace("kill.destroy");
			removeChild(skin);
			skin = null;
			removeChild(qModule);
			qModule = null;
			removeChild(pModule);
			pModule = null;
			
		}
		
		private function onKeyboardChk(e:KeyboardEvent):void
		{
			
			var i:int = e.charCode;
			
				switch(i)
				{
					
					case 112: // p
						
						trace("p was pressed. pause da game");
						pModule.init();
						pModule.visible = true;
						
						break;
						
					case 113: // q
					
						trace("q was pressed. ask dem 2 quitt!!");
						qModule.init();
						qModule.visible = true;
						break;
						
							default:
								
								break;
				}
		}
		
		private function onPauseClick(e:MouseEvent):void
		{
			
			Main.iFX.pauseCurrentTrack();
			
		}
		
		private function onMusicClick(e:MouseEvent):void
		{
			
			Main.iFX.toggleSoundState();
			
		}
	}
}
			